home *** CD-ROM | disk | FTP | other *** search
/ Aminet 3 / Aminet 3 - July 1994.iso / Aminet / dev / lang / J4thDemo.lha / Programs / quarters.f < prev    next >
Encoding:
FORTH Source  |  1992-09-08  |  1.2 KB  |  54 lines

  1. \ This is a simple little word that accepts some number of
  2. \ quarters (25 cents) and tells you how many dollars and cents
  3. \ they equate to.
  4. \
  5. \ It simply divides the number of quarters by 4, with remainder.
  6. \
  7. \ The number of times 4 goes into the number of quarters equals
  8. \ the number of dollars.
  9. \
  10. \ The remainder times 25 equals the cents component.
  11. \
  12. \ Mike Haas, for the JForth Demo package.
  13.  
  14. anew task-Quarters.f
  15.  
  16. : Quarters  ( numQuarters -- , prints out answer )
  17.  
  18.   \ make sure numbers will be processed in base 10...
  19.  
  20.   decimal
  21.  
  22.   \ Print out how many quarters...
  23.  
  24.   >newline  ( -- numQuarters )
  25.   dup       ( -- numQuarters numQuarters )
  26.   .         ( -- numQuarters )
  27.   
  28.   ." quarters equals $"
  29.  
  30.   \ divide number by 4, with remainder
  31.  
  32.   4 /mod    ( -- numQuarters #dollars )
  33.   
  34.   \ print #dollars without trailing space that normal '.' has...
  35.   
  36.   0 .r      ( -- numQuarters )
  37.   
  38.   \ print the decimal point
  39.   
  40.   ." ."
  41.   
  42.   \ print remaining cents  (with a leading '0' if necessary)
  43.   
  44.   25 *        ( -- #cents )
  45.   dup 10 <    ( -- #cents flag )   \ is it 9 or less?
  46.   IF
  47.      ." 0"
  48.   THEN
  49.   0 .r   cr
  50. ;
  51.  
  52.  
  53. cr ." 'QUARTERS' compiled...   Try:   74326 quarters" cr cr
  54.